package cn.kinggm520.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 作者: kinggm Email:731586355@qq.com
 * 时间:  2020-05-22 23:27
 */

@Configuration
public class RabbitMQConfig {
    //    交换机名称
    public static final String TOPIC_EXCHANGE1 = "goods_topic_exchange";

    //    队列名称
    public static final String QUEUE1 = "goods_queue";

    //    声明交换机
    @Bean("goods_topic_exchange")
    public Exchange funoutExchange() {
        return ExchangeBuilder.topicExchange(TOPIC_EXCHANGE1).durable(true).build();
    }


    //    声明队列
    @Bean("goods_queue")
    public Queue queue2() {
        return QueueBuilder.durable(QUEUE1).build();
    }


    //    绑定队列和交换机
    @Bean
    public Binding funoutExchangeBinding1(@Qualifier("goods_queue") Queue queue, @Qualifier("goods_topic_exchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("goods.#").noargs();
    }


}
